<template>
  <el-dialog
    draggable
    overflow
    :title="titleMap[mode]"
    v-model="visible"
    :width="400"
    destroy-on-close
    @closed="$emit('closed')"
  >
    <el-tabs type="border-card">
      <el-tab-pane ref="tab" label="基础信息">
        <el-form
          :model="form"
          :rules="rules"
          ref="dialogForm"
          label-width="100px"
          label-position="right"
        >
          <el-row>
            <el-col :span="20">
              <el-form-item label="状态日期" prop="invoice_status_date">
                <el-date-picker
                  v-model="form.invoice_status_date"
                  type="date"
                  value-format="YYYY-MM-DD"
                  placeholder="状态日期"
                >
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="20">
              <el-form-item label="状态" prop="invoice_status_id">
                <skDicSelect
                  v-model="this.form.invoice_status_id"
                  :code="'invoice_status'"
                ></skDicSelect>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-tab-pane>
    </el-tabs>

    <template #footer>
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
    </template>
  </el-dialog>
</template>

<script>
import tool from "@/utils/tool";
import skDicSelect from "@/components/skDicSelect";
export default {
  emits: ["success", "closed"],
  components: { skDicSelect },
  data() {
    return {
      mode: "edit",
      titleMap: {
        add: "新增",
        edit: "编辑状态",
      },
      form: {
        invoice_status_date: tool.SYS_DATE(),
      },
      rules: {
        invoice_status_date: [{ required: true, message: "日期必选" }],
        invoice_status_id: [{ required: true, message: "状态必选" }],
      },
      visible: false,
      isSaveing: false,
    };
  },
  mounted() {},
  methods: {
    //显示
    open(mode = "add") {
      this.mode = mode;
      this.visible = true;

      return this;
    },
    //表单提交方法
    submit() {
      this.$refs.dialogForm.validate(async (valid) => {
        if (valid) {
          this.isSaveing = true;

          var res = await this.$API.finance.invoice.invoice_status.post(this.form);
          this.isSaveing = false;
          if (res.code == 200) {
            this.$emit("success", this.form, this.mode);
            this.visible = false;
            this.$message.success("操作成功");
          }
        }
      });
    },
    //表单注入数据
    setData(data) {
      Object.assign(this.form, data);
    },
  },
};
</script>

<style></style>
